{include file="common/header"/}
 <a href="javascript:location.replace(location.href);" style="float:right" class="layui-btn layui-btn-blue refreshs"><i class="fa fa-history falocation" aria-hidden="true"></i>
        </a>
<div class="fadeInUp animated headalert"><br>
    <div class="layui-anim layui-anim-up">
        <form class="layui-form">
            <div class="layui-container">
                <div class="layui-row">
                    <div class="layui-form-item">
                        <label class="layui-form-label">头像</label>
                        <input type="hidden" name="avatar" id="avatar">
                        <div class="layui-input-block">
                            <div class="layui-upload">
                                <button type="button" class="layui-btn layui-btns layui-btn-blue" id="adBtn"><i class="layui-icon" style="color: #fff">&#xe67c;</i>点击上传</button>
                                <div class="layui-upload-list">
                                    <img class="layui-upload-img" id="adPic" style="border-radius: 50%;">
                                    <p id="demoText"></p>
                                </div>
                            </div>
                        </div>
                    <div class="layui-form-item">
                      <label class="layui-form-label"></label>
                      <div class="layui-input-4">
                          <div class="layui-progress layui-progress-big layui-col-md4" lay-showPercent="yes" lay-filter="progressBar">
                              <div class="layui-progress-bar layui-btn-blue" lay-percent="0%" ></div>
                          </div>
                      </div>
                    </div>
              </div>
            </div>
        </form>
    </div>   
</div> 
{include file="common/footer"/}
<script>
var url = '{:url("adminadd")}';
layui.use(['form','layer','upload','element'], function(){
    var form = layui.form
    ,layer = layui.layer
    ,upload = layui.upload
     ,element = layui.element
    ,$ = layui.jquery;

    //监听提交
    form.on('submit(add)', function(data){
      $.post(url,data.field,function(res){
          if(res.code == 1){
              layer.msg(res.msg);
              setTimeout(function(){
                  window.parent.location.reload();//修改成功后刷新父界面
              }, 1000);
          }else{
            layer.msg(res.msg); 
          }
      },'json')
        return false;
    }); 
    //普通图片上传
    var uploadInst = upload.render({
          elem: '#adBtn'
          ,url: '{:url("Upfiles/upimages1")}'
          , method: 'post' 
          ,before: function(obj){
            loading =layer.msg('加载中', {
            ,shade:[0.1, '#fff']
            ,time:false
          });
              //预读本地文件示例，不支持ie8
              this.data={files:'admin'};//关键代码
          }
           ,progress: function(e , percent) {
            element.progress('progressBar',percent  + '%');
        },
          done: function(res){
           if(res.code>0){
            layer.close(loading);
                  $('#adPic').show();
                  $('#adPic').attr('src', '__PUBLIC__'+res.src);
                  $("#adPic").css({"width":80+"px","height":80+"px"});
                  $('#avatar').val(res.src);
              }else{
                  //如果上传失败
                  layer.msg('上传失败');
              }
          }
          ,error: function(){
             layer.msg('上传失败');
          }
    });
});
</script>
